<?php
defined('BASEPATH') OR exit('No direct script access allowed');

//会员体态信息
class Titai extends MY_Controller {

	function __construct(){
		parent::__construct();
		
	}	

	//start
	/**
	* @name 添加会员体态
	* @param uid ture int 会员ID
	* @param config_id ture int 体态配置id	
	* @param standard ture int 是否标准
	* @param info ture char 评估情况
	* @param img false char 图片链接
	* @return 返回数据列表
	*/
	//end
	function add_titai(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);		
		$config_id = $this->input->post('config_id',null,0);		
		
		$arr = array(
			'standard'=>$this->input->post('standard',null,0),
			'info'=>$this->input->post('info',null,''),
			'img'=>$this->input->post('img',null,''),
		);
		$arr['config_id'] =  $config_id;		
		$ver_arr = array(
			'config_id'=>"评估配置不能为空",
			'info'=>"评估情况不能为空",
		);
		$result = $this->CheckData($ver_arr,$arr);
		
		if($result){
			$this->err_out($result);
		}
		$this->load->model('User/MemberTitaiModel','titai');
		$row = $this->titai->pos_get_info($uid,$config_id);
		
		$this->load->model('User/MemberTitaiConfigModel','titaiConfig');
		$config_info = $this->titaiConfig->get_info($config_id);
		if(!$config_info){			
			$this->err_out("体态配置错误");
		}
		//$arr['type'] = $config_info['type'];
		
		if($row){
			$this->titai->edit($arr,"id='{$row['id']}'");
		}
		else{
			$arr['user_id'] =  $uid;			
			$this->titai->add($arr);
		}
		
		$this->data_out($arr);
	}
	
	//start
	/**
	* @name 获取体态评估菜单
	* @param type ture int 0正面观 1后面观 2侧面观 
	* @return 返回数据列表
	*/
	//end
	function get_pg_config(){
		$user_id = $this->user_id;	
		$type = $this->input->post('type',null,0);
		
		$this->load->model('User/MemberTitaiConfigModel','titaiconfig');
		$list = $this->titaiconfig->get_lists(array("type"=>$type));
		
		$this->data_out($list);
	}
	
	//start
	/**
	* @name 获取会员体态
	* @param uid ture int 会员ID
	* @param type ture int 0.正面，1.后面2.侧面
	* @return 返回数据列表 list（会员体态记录） remark_list（体态说明）
	*/
	//end
	function get_titai(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);
		$type = $this->input->post('type',null,0);
		
		$arr = array();
		
		$this->load->model('User/MemberTitaiConfigModel','titaiconfig');
		$list = $this->titaiconfig->type_get_data($type,$uid);
					
		
		$arr['list'] = $list;
		
		$this->load->model('User/MemberTitaiRemarkModel','titaiRemark');
		$remark_list = $this->titaiRemark->get_lists(array("type"=>$type));
		$arr['remark_list'] = $remark_list;
		
		$this->data_out($arr);
	}
	//start
	/**
	* @name 获取会员身体数据
	* @param uid ture int 会员ID
	* @param page ture int 页面
	* @return 返回数据列表
	*/
	//end
	function get_base_info(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);
		$page = $this->input->post('page',null,1);
		if(!$page){
			$this->err_out('页面不能小于1');
		}
		
		
		$this->load->model('User/MemberPhysicalModel','Physica');
		$res = $this->Physica->get_data($uid,$page);
		
		if(!$res){
			$this->err_out('没有数据');
		}
		
		$info = $res['data'];
		
		$info['whr'] = 0;
		if(!empty($info['waist']) && !empty($info['hipline'])){
			$info['whr'] = $info['waist']/$info['hipline'];
		}
		$info['whr'] = round($info['whr'],2);
		
		$data = array();
		$data['data'] = $info;
		$data['count'] = $res['count'];
		$data['date'] = $res['date'];
		
		$this->data_out($data);
	}
	
	//start
	/**
	* @name 获取会员目标数据
	* @param uid ture int 会员ID
	* @return 返回数据列表
	*/
	//end
	function get_targent_info(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);
		
		$this->load->model('User/MemberPhysicalTargentModel','targent');
		$info = $this->targent->get_data($uid);
		
		
		$info['whr'] = 0;
		if(!empty($info['waist']) && !empty($info['hipline'])){
			$info['whr'] = $info['waist']/$info['hipline'];
		}
		$info['whr'] = round($info['whr'],2);
		
		$this->data_out($info);
	}
}
